import { post, postJson, _axios, download } from "../util/http"
/**
 * 登录
 * @param  params 
 */
export const LoginRequest = params => post(`/user/login`, params)

/**
 * 修改密码
 * @param  params 
 */
export const UpdatePwd = params => post(`/user/pwd/update`, params)
/**
 * 发送验证码
 * @param  params 
 */
export const sendEcode = params => post(`/user/sendEcode`, params)
/**
 * 验证码登录
 * @param  params 
 */
export const phoneLogin = params => post(`/user/phoneLogin`, params)
/**
 * 加载用户数量信息
 * @param  params 
 */
export const SelectUserNumber = params => post(`/user/selectUserNumber`, params)

/**
 * 注册
 * @param  params 
 */
export const RegisterRequest = params => post(`/user/register`, params)

/**
 * 登出
 * @param  params 
 */
export const LogoutRequest = params => post(`/user/logout`, params)

/**
 * 注册
 * @param  params 
 */
export const registerEcode = params => post(`/user/registerEcode`, params)

/**
 * 密码找回
 * @param  params 
 */
export const RegisterUppwd = params => post(`/user/uppwd`, params)


/**
 * 获取JWT
 * @param  params 
 */
export const GetJWT = params => post(`/user/jwt`, params)

/**
 * 自动登录
 * @param  params 
 */
export const AutoLogin = params => post(`/user/autoLogin`, params)

/**
 * 获取配置
 */
export const getSetting = params => post('/setting/get', params)

/**
 * 设置配置
 */
export const setSetting = params => post('/setting/save', params)
/**
 * 获取门户地址
 */
export const GetGatewayUrl = params => post('/setting/getGatewayUrl', params)
/**
 * 获取应用名称
 */
export const GetAppName = params => post('/setting/getAppName', params)

/**
 * 查询日志列表
 * @param  params 
 */
export const SelectLogsPage = params => post(`/logs/selectPage`, params)

/**
 * 查询审计日志列表
 * @param  params 
 */
export const SelectAuditLogsPage = params => post(`/audit/selectPage`, params)

/**
 * 保存角色
 * @param  params 
 */
export const SaveRole = params => postJson(`/role/save`, params)

/**
 * 分页列表角色
 * @param  params 
 */
export const SelectPageRole = params => post(`/role/selectPage`, params)

/**
 * 角色列表
 * @param  params 
 */
export const SelectListRole = params => post(`/role/selectList`, params)

/**
 * 角色删除
 * @param  params 
 */
export const DeleteRole = params => post(`/role/delete`, params)
/**
 * 查询角色拥有菜单
 * @param  params 
 */
export const GetRoleMenu = params => post(`/role/menu/selectList`, params)

/**
 * 获取配置
 * @param  params 
 */
export const getConfig = params => post(`/setting/getConfig`, params)


/**
 * 保存配置
 * @param  params 
 */
export const SaveConfig = params => postJson(`/setting/saveConfig`, params)



/**
 * 文件查询列表
 * @param  params 
 */
export const selectFiles = params => post(`/file/selectList`, params)

/**
 * 删除文件
 * @param  params 
 */
export const DeleteFile = params => post(`/file/delete`, params)

/**
 * 获取菜单
 * @param  params 
 */
export const GetAllMenu = params => post(`/menu/selectList`, params)
/**
 * 获取菜单
 * @param  params 
 */
export const GetMenu = params => post(`/menu/getAppMenu`, params)

/**
 * 上传附件
 *
 * @param {Object}
 * @return Result
 */
export const UploadFile = (params, callback) => _axios.post('/file/upload', params, {
  headers: { 'Content-Type': 'multipart/form-data' },
  onUploadProgress (progressEvent) {
    if(progressEvent.lengthComputable){
      //属性lengthComputable主要表明总共需要完成的工作量和已经完成的工作是否可以被测量
      //如果lengthComputable为false，就获取不到progressEvent.total和progressEvent.loaded
      if (callback) {
        callback(progressEvent);
      }
    }
  }
})

/**
 * 下载
 * @param  params 
 */
export const DownloadFile = (fileName, params) => download(`/file/download`,fileName, params)

/**
 * 获取 base64
 * @param  params 
 */
export const GetFileBase64 = params => post(`/file/getBase64`, params)

/**
 * 列表
 * @param  params 
 */
export const SelectListFile = params => post(`/file/selectList`, params)

/**
 * 删除
 * @param  params 
 */
export const DeleteHandleFile = params => post(`/file/delete`, params)

/**
 * 扫码登录
 * @param  params 
 */
export const ScanLogin = params => post(`/user/scan/login`, params)